<?php
//include_once("../modules/checkA.php");
//include_once("../../config.php");
//?>



<?
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel2007.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel5.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/IOFactory.php';
?>



<?


date_default_timezone_set('Europe/London'); //设置时间



$inputFileName = ROOT_PATH_.'/uploadfiles/'.$name;

//判断一下，文件是2007还是旧版的excel
if(strstr($name,".")==".xls")
{
    $inputFileType = 'Excel5';
}
else if(strstr($name,".")==".xlsx")
{
    $inputFileType = 'Excel2007';
}
else
{
    echo "请检查文件格式";
}




//echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
/*
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列
*/
$objWorksheet = $objPHPExcel->getActiveSheet();//取得总行数
$highestRow = $objWorksheet->getHighestRow();//取得总列数

echo 'highestRow='.$highestRow;
//echo "<br>";
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
echo 'highestColumnIndex='.$highestColumnIndex;
//echo "<br />";



$headtitle=array();
$result=array();


for ($row = 0;$row <= $highestRow;$row++)
{
    $strs=array();
    //注意highestColumnIndex的列数索引从0开始
    for ($col = 0;$col < $highestColumnIndex;$col++)
    {
        $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();

        $result[$row][$col]=$strs[$col];
    }


}



print_r2($result);



 //已经拥有数组，然后按照这个数组，去批量插入数据。




//设置需要搜索的表格的前缀后缀
$table_Suffix = "course_record";
$table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀




$date=date("Y-m-d h:m:s");

//如果第一行有标题的话，i就设置从1算起。

for($i=1;$i<count($result);$i++)
{


    $values="('$date','".$result[$i][0]."','".$result[$i][2]."'),".$values;


}

$values=rtrim($values, ',');



echo $sql = "INSERT INTO $table (
date,
membernid,
coursenid
)

value $values ";


$query = mysql_query($sql) or die ('添加数据失败！！');


mysql_close($con);








?>